package com.example.maomao.myapplication;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;

public class MaoActivity extends AppCompatActivity {
    private Context context;
    private GridView grid;
    private BaseAdapter mAdapter = null;
    private ArrayList<GridItem> mData = null;
    private int[] imageId = {R.mipmap.fourth1,R.mipmap.fourth2,R.mipmap.fourth3,R.mipmap.fourth4,
            R.mipmap.fourth5,0,0,0,0};
    private String[] name = {"收藏","意见反馈","分享","关于","退出","","","",""};



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mao);
        //调取函数
        openGirdView();
        openButton();




    }

    public void openGirdView(){
        context = MaoActivity.this;
        grid = (GridView) findViewById(R.id.gridView);

        mData = new ArrayList<GridItem>();
        for (int i = 0; i < imageId.length; i++) {
            mData.add(new GridItem(imageId[i],name[i]));
        }

        mAdapter = new MyAdapter<GridItem>(mData,R.layout.grid_item) {
            public void bindView(ViewHolder holder,GridItem obj){
                holder.setImageResource(R.id.gridImage, obj.getId());
                holder.setText(R.id.gridText, obj.getName());
            }
        };
        grid.setAdapter(mAdapter);
        grid.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                Toast.makeText(context,"你点击了~"+position+"~项",Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void openButton(){
        Button button1 = (Button) findViewById(R.id.loginBut1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MaoActivity.this,PhoneLogin.class);
                startActivity(intent);
            }
        });
    }


}

